<template>
	<s-layout class="wallet-wrap" title="合伙人分红" :navbar="'normal'" :bgStyle="{ color: '#fff' }">
		<!-- 钱包卡片 -->
		<su-sticky>
			<view class="" style="background-color: #fff;position:sticky;">
				<view class="header-box ss-flex ss-row-center ss-col-center">
					<view class="card-box" :style="{backgroundImage:'url('+sheep.$url.static('static/board_bg.png')+')'}">
						<view class="card-head ss-flex ss-col-center">
							<view class="card-title ss-m-r-10">历史业绩总额（半年）</view>
						</view>
						<view class="ss-flex ss-row-between ss-col-center ss-m-t-60">
							<view class="money-num">￥{{ userInfo.self_performance || '0.00' }}
							</view>
						</view>
					</view>
				</view>
				<view class="grey-box ss-p-x-24 ss-p-t-34">
					<text class="title ss-m-t-14 ss-line-1" style="color: #979797;">
						有效大市场业绩
						<text class="" style="color: #000;">
							￥{{ userInfo.big_market || '0.00' }}
						</text>
					</text>
					<view class="title ss-m-t-10 ss-line-1" style="color: #979797;">
						有效小市场业绩
						<text class="" style="color: #000;">
							￥{{ userInfo.small_market || '0.00' }}
						</text>
					</view>
				</view>
				<!-- 统计 -->
				<view class="filter-box ss-p-x-30 ss-p-y-10">
					<view class="bg ss-flex">
						<view class="left-box ss-m-r-10"></view>
						<view class="total-box">分红明细</view>
					</view>
				</view>
			</view>
		</su-sticky>
		<s-empty v-if="state.pagination.total === 0" text="暂无数据" icon="/static/data-empty.png" />
		<!-- 钱包记录 -->
		<view v-if="state.pagination.total > 0">
			<view class="wallet-list ss-flex border-bottom ss-p-24 ss-m-x-30 ss-m-b-20 ss-m-t-14" v-for="item in state.pagination.data"
				:key="item.id">
				<view class="list-content">
					<view class="title-box ss-flex ss-row-between ss-m-b-16">
						<view class="money">{{ item.bonus }}</view>
						<text class="time ss-line-1">{{ item.createtime_text }}</text>
					</view>
					<view class="line ss-m-b-20"></view>
					<view class="title-box ss-flex ss-row-between">
						<text class="title ss-line-1">大市场扣除：{{ item.big_market }}</text>
						<view class="title ss-line-1">
							小市场扣除：{{ item.small_market }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{
        contentdown: '上拉加载更多',
      }" />
	</s-layout>
</template>

<script setup>
	import {
		computed,
		watch,
		reactive
	} from 'vue';
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
	import sheep from '@/sheep';
	import dayjs from 'dayjs';
	import _ from 'lodash';

	const headerBg = sheep.$url.css('/assets/addons/shopro/uniapp/user/wallet_card_bg.png');

	const pagination = {
		data: [],
		current_page: 1,
		total: 1,
		last_page: 1,
	};
	// 数据
	const state = reactive({
		date: [],
		pagination,
		loadStatus: '',
	});

	const userInfo = computed(() => sheep.$store('user').userInfo);

	async function getList(page = 1, list_rows = 8) {
		state.loadStatus = 'loading';
		let res = await sheep.$api.commission.dividendLog({
			list_rows,
			page,
		});
		if (res.code === 1) {
			state.pagination.data = _.concat(state.pagination.data, res.data.data);
			if (state.pagination.current_page < state.pagination.last_page) {
				state.loadStatus = 'more';
			} else {
				state.loadStatus = 'noMore';
			}
		}
	}
	onLoad(async (options) => {
		getList();
	});

	onReachBottom(() => {
		if (state.loadStatus !== 'noMore') {
			getList(state.pagination.current_page + 1);
		}
	});
</script>

<style lang="scss" scoped>
	.wallet-wrap {
		height: 100vh;
	}

	.grey-box {
		background-color: #F5F5F5;
		margin: 30rpx 30rpx 10rpx;
		height: 150rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		margin-top: -64rpx;
	}

	.header-box {
		background-color: $white;
		padding: 30rpx;

		.card-box {
			width: 100%;
			min-height: 244rpx;
			padding: 40rpx;
			background-size: 100% 100%;
			border-radius: 30rpx;
			overflow: hidden;
			position: relative;
			z-index: 1;
			box-sizing: border-box;

			&::after {
				content: '';
				display: block;
				width: 100%;
				height: 100%;
				z-index: 2;
				position: absolute;
				top: 0;
				left: 0;
				background: v-bind(headerBg) no-repeat;
				pointer-events: none;
			}

			.card-head {
				color: $white;
				font-size: 30rpx;
			}

			.money-num {
				font-size: 50rpx;
				line-height: 50rpx;
				font-weight: 500;
				color: $white;
				font-family: OPPOSANS;
			}
		}
	}

	// 筛选

	.filter-box {
		height: 40rpx;
		background-color: #fff;

		.bg {
			width: 20%;
		}

		.total-box {
			font-size: 29rpx;
			font-weight: 500;
		}

		.left-box {
			width: 4rpx;
			height: 30rpx;
			background: #E84010;
		}
	}

	// 钱包记录
	.wallet-list {
		box-shadow: 0 0 8rpx 8rpx #f3f3f4;
		border-radius: 20rpx;
		background-color: #ffff;

		.money {
			font-size: 28rpx;
			font-family: OPPOSANS;
			color: #E84010;
		}
	}
</style>